package com.e2edour.biz.impl

import com.e2edour.facade.WeiXinManagerFacade
import com.e2edour.facade.abc.CommonResponse
import com.e2edour.facade.enums.ResCodeEnum
import com.e2edour.facade.req.{WeiXinCheckSignatureReq, WeiXinMsgReq}
import com.e2edour.facade.res.{WeiXinMsgBean, WeiXinMsgRes}
import com.e2edour.service.WeiXinManagerService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
  * <p>
  *
  * @author King 
  * @since 2017/1/17
  */
@Service("WeiXinManagerFacade")
class WeiXinManagerFacadeImpl extends WeiXinManagerFacade {

  @Autowired
  var managerService: WeiXinManagerService = _

  /**
    * 处理微信消息
    *
    * @param req
    * @return
    */
  override def handlerMsg(req: WeiXinMsgReq): WeiXinMsgRes = {
    val res = new WeiXinMsgRes
    val bean = new WeiXinMsgBean
    val msg = managerService.handlerMsg(req);
    bean.setMsg(msg)
    res.setDataObject(bean)
    res
  }

  /**
    * 微信验证签名
    *
    * @return
    */
  override def checkSignature(req: WeiXinCheckSignatureReq): CommonResponse = {
    val res: CommonResponse = new CommonResponse
    val result = managerService.checkSignature(req.getTimestamp, req.getNonce, req.getSignature)
    if (!result) {
      res.setResCode(ResCodeEnum.biz_error_1.id)
      res.setResDesc(ResCodeEnum.biz_error_1.toString)
    }
    res
  }
}
